package com.yuma.completablefuture;

import java.util.concurrent.*;

public class CompletableFutureDemo2 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {

        ThreadPoolExecutor threadPool = new ThreadPoolExecutor(10, 20, 60, TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(), Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());

        CompletableFuture<Integer> icf = CompletableFuture.supplyAsync(() -> {
            System.out.println("supplyAsync...");
            return 1;
        }, threadPool)
//        .thenRun(()->{
//            System.out.println("run....");
//        });
//        .thenAccept(t->{
//            System.out.println("Accept t:" + t);
//        });
        .thenApplyAsync(t -> {
            System.out.println("apply t:" + t);
            return 2;
        });

        System.out.println("icf = " + icf.get());
        System.out.println("main over");
        threadPool.shutdown();
    }
}
